<?
session_start();
REQUIRE ("../../include/protect/connect.php");             //Pour se connecter a la base.
REQUIRE ("../../include/fonction.php");             //Pour les fonction PHP


$PAGE="<SCRIPT TYPE=\"text/javascript\" SRC=\"../../include/common_script.js\"></SCRIPT>";





//Ajouter une facture
$QUERY="INSERT INTO commande (facture_user, facture_client, facture_m_total, facture_date,facture_comment) VALUES ($_USER, $_USER_ID, $_TOTAL, NOW(),'$_COMMENT')";
$resultat=mysql_query($QUERY);

     echo $QUERY;

//Aller chercher l'ID de la facture
$QUERY="SELECT facture_id FROM commande WHERE facture_user=$_USER AND  facture_client=$_USER_ID AND facture_m_total=$_TOTAL AND facture_comment='$_COMMENT' ORDER BY facture_date DESC LIMIT 0,1 ";
$resultat=mysql_query($QUERY);
$tmp=mysql_fetch_array($resultat);
$FACTURE_ID=$tmp[0];

//Ajouter les articles

$article=explode("/",$_COMM_ART);

 FOREACH($article as $tmp_article){

      $var_tmp=EXPLODE("-",$tmp_article);


      $QUERY="SELECT article_id,article_prix_htva,article_code_tva FROM article WHERE article_id=$var_tmp[0]";
      $resultat=mysql_query($QUERY);
      $tmp=mysql_fetch_array($resultat);

      $QUERY="INSERT INTO commande_detail (detail_fature_id, detail_article, detail_quantite, detail_prixu, detail_tva,detail_cadeau)
      VALUES ($FACTURE_ID,$var_tmp[0],$var_tmp[1],$tmp[1], $tmp[2],0)";
      $resultat=mysql_query($QUERY);


}//Fin du foreach


//Ajouter les cadeaux

$article=explode("/",$_COMM_CAD);

 FOREACH($article as $tmp_article){

      $var_tmp=EXPLODE("-",$tmp_article);


      $QUERY="SELECT article_id,article_prix_htva,article_code_tva FROM article WHERE article_id=$var_tmp[0]";
      $resultat=mysql_query($QUERY);
      $tmp=mysql_fetch_array($resultat);

      $QUERY="INSERT INTO commande_detail (detail_fature_id, detail_article, detail_quantite, detail_prixu, detail_tva,detail_cadeau)
      VALUES ($FACTURE_ID,$var_tmp[0],$var_tmp[1],$tmp[1], $tmp[2],1)";
      $resultat=mysql_query($QUERY);





}//Fin du foreach

  $MESSAGE=addslashes(MESSAGE_01('Vous avez ajouter une commande avec succes.','checkin2.png'));

 $PAGE.="<script language=\"javascript\">
      var contenu =\"$MESSAGE\";
      changecontenu(contenu,'div_inner_message');div_app('div_message');
      </script> ";
 mysql_close(); ECHO $PAGE;  EXIT;





?>
